Ext.ns("App");
Ext.ns("Ext.app");

Ext.util.Observable.observeClass(Ext.data.Connection);
Ext.data.Connection.on("requestcomplete", function(conn, resp, options) {
   if(resp.status != 200) {
       alert("error:" + resp.statusText + " status:" + resp.status);
   }
});

App.init = function() {
    Ext.QuickTips.init();
    Ext.BLANK_IMAGE_URL = ctxPath + '/resources/images/default/s.gif';

    var megBtn = new Ext.Button({
        id:'messageTip',
        hidden:true,
        width:50,
        height:20,
        handler:function() {
            var megBtn = Ext.getCmp('messageTip');
            var megWin = Ext.getCmp('win');

            if(megWin == null) {
                new MessageWin();
            }
            megBtn.hide();
        }
    });

    var tabPanel = new Ext.TabPanel({
        id:'centerTabPanel',
        region:'center',
        deferredRender:true,
        enableTabScroll:true,
        activeTab:0,
        defaults:{
            autoScroll:true,
            closable:true
        },
        items:[App.home.portal]
    });

    var westPanel = new Ext.Panel({
        region:'west',
        id:'west-panel',
        title:'Navigation',
        split:true,
        width:200,
        autoScroll:true,
        layout:'accordion',
        collapsible:true,
        margins:'0 0 0 2',
        items:[],
        bbar: new Ext.Toolbar({
            width:'100%',
            height:25,
            items:[{
                text:'Logout',
                iconCls:'btn-logout',
                handler:function() {
                    App.login.logout();
                }
            },'->',{
                text:'Whoes on line',
                iconCls:'btn-onlineUser',
                handler:function(){
                    //TODO
                }
            }]
        })
    });

    var viewport = new Ext.Viewport({
        layout:'border',
        items:[{
            xtype:'panel',
            frame:true,
            region:'north',
            height:68,
            layout:'border',
            bodyStyle:'',
            layoutConfig:{
                pack:'left',
                align:'middle'
            },
            defaults:{
                border:false
            },
            items:[{
                region:'west',
                html:'<img src="'+ctxPath+'/images/ht-logo.png/>'
            },{
                region:'center',
                layout:'hbox',
                layoutConfig:{
                    padding:'5',
                    pack:'center',
                    align:'middle'
                },
                defaults:{
                    margins:'0 5 0 0'
                },
                items:[{
                    xtype:'label',
                    text:'input keyword'
                },{
                    xtype:'textfield',
                    name:'keySearch',
                    width:200,
                    id:'keySearch'
                },{
                    xtype:'button',
                    iconCls:'btn-search',
                    text:'Search',
                    handler:function(){
                        alert('search undo');
                    }
                }]
            },{
                region:'east',
                html:'<img src="' + ctxPath+'/images/product.png/>'
            }]
        }, westPanel, tabPanel, {
            xtype:'panel',
            region:'south',
            height:28,
            border:false,
            bbar:[megBtn,'->',
                {
                    xtype:'tbfill'
                },
                new Ext.Toolbar.TextItem('management system'),
                {
                    xtype:'tbseparator'
                },
                new Ext.Toolbar.TextItem('Tech Support'),
                {
                    xtype:'tbseparator'
                },{
                    pressed:false,
                    text:'Contact',
                    handler:function() {
                        Ext.Msg.alert('Contact', 'Tel: 023');
                    }
                }]
        }]
    });
}

Ext.onReady(App.init);